package com.foreveross.crawl.vo;

import java.io.Serializable;
import java.util.concurrent.atomic.AtomicInteger;

import org.apache.log4j.Logger;

/** 
 * @ClassName: 任务数据统计 
 * @Description: TODO
 * @author luofangyi
 * @date 2014-7-11 下午6:11:16 
 *  
 */ 
public class TaskStatisticsBeta1 implements Serializable {

	/**
	 * 
	 */
	private static final long serialVersionUID = 4851654913811460769L;
	
	private static Logger logger = Logger.getLogger(TaskStatisticsBeta1.class);

	/**
	 * 任务总数
	 */
	private AtomicInteger taskTotal = new AtomicInteger(0);
	
	/**
	 * 执行中的任务数
	 */
	private AtomicInteger taskDoing = new AtomicInteger(0);
	
	/**
	 * 执行异常任务数
	 */
	private AtomicInteger taskException = new AtomicInteger(0);
	
	/**
	 * 成功的任务数
	 */
	private AtomicInteger taskSuccess = new AtomicInteger(0);

	public int getTaskTotal() {
		return taskTotal.get();
	}

	public void setTaskTotal(int taskTotal) {
		this.taskTotal.set(taskTotal);
	}

	public int getTaskDoing() {
		synchronized (TaskStatisticsBeta1.class) {
			return taskDoing.get();
		}
	}

	public void setTaskDoing(int taskDoing) {
		synchronized (TaskStatisticsBeta1.class) {
			this.taskDoing.set(taskDoing);
		}
	}

	public int getTaskException() {
		return taskException.get();
	}

	public void setTaskException(int taskException) {
		this.taskException.set(taskException);
	}

	public int getTaskSuccess() {
		return taskSuccess.get();
	}

	public void setTaskSuccess(int taskSuccess) {
		this.taskSuccess.set(taskSuccess);
	}

	public void addTotal(){
		synchronized (TaskStatisticsBeta1.class) {
			this.taskTotal.incrementAndGet();
		}
	}
	
	public void addTotal(int number){
		synchronized (TaskStatisticsBeta1.class) {
			this.taskTotal.addAndGet(number);
		}
	}

	public void addDoing(){
		synchronized (TaskStatisticsBeta1.class) {
			this.taskDoing.incrementAndGet();
		}
	}
	
	public void addSuccess(){
		synchronized (TaskStatisticsBeta1.class) {
			this.taskSuccess.incrementAndGet();
			this.taskDoing.decrementAndGet();
		}
	}
	
	public void addSuccess(int number){
		this.taskSuccess.addAndGet(number);
	}
	
	public void addFail(){
		this.taskException.incrementAndGet();
		this.taskDoing.decrementAndGet();
	}
	
	public void addFail(int number){
		this.taskException.addAndGet(number);
	}
}
